angular.module('App')
    .controller('MessagesController',
    function ($scope, $ionicPopover, $ionicTabsDelegate, TabsViews) {
        // 从 A 视图切换到 B 视图时，事件的顺序是
        // B控制器创建 -> B beforeEnter -> A beforeLeave
        // B enter -> A leave -> B afterEnter -> A afterLeave

        $ionicPopover.fromTemplateUrl('popover', {
            scope: $scope
        }).then(function (popover) {
            $scope.popover = popover;
        });


        $scope.openPopover = function ($event) {
            $scope.popover.show($event);
        };
        $scope.closePopover = function () {
            $scope.popover.hide();
        };

        $scope.$on('$destroy', function () {
            $scope.popover.remove();
        });
    })